<?php
namespace App\Http\Controllers\Admin;


use App\Models\CompanyPhoto;
use Illuminate\Http\Request;
/**
 *
 * @author Joker
 *        
 */
class CompanyPhotoController extends BaseController
{
    
    /**
     * 获取所有企业相片列表
     */
    public function index()
    {
        if(!$this->user->can('viewCompanyPhoto')) abort(405);
        
        $images = CompanyPhoto::paginate(20);
        
        return view("admin.enterprise.photo.index")->with('images',$images);
    }
    
    /**
     *  删除图片
     */
    public function destroy(Request $request)
    {

        if(!$this->user->can('deleteCompanyPhoto'))
            return $this->formatJson('error',$this->permerror);

        $id = $request->input('id');
        $imageinfo = CompanyPhoto::find($id);

        if(empty($imageinfo))
        {
            return  $this->formatJson('falied','抱歉，资源不存在!');
        }
        else
        {
            $imageinfo->delete();
            unlink(public_path($imageinfo->path));
            return $this->formatJson('success','图片删除成功！');
        }
    }
}